package com.steel.yfmall.cloud.assistant.common.impl;

import com.steel.yfmall.cloud.assistant.common.SteelSystemRegionAreaInfoService;
import com.steel.yfmall.cloud.assistant.common.mapper.SteelSystemRegionAreaInfoBeanMapper;
import com.steel.yfmall.cloud.assistant.dto.para.common.ParaSteelSystemRegionAreaInfo;
import com.steel.yfmall.cloud.assistant.po.common.SteelSystemRegionAreaInfoBean;
import com.steel.yfmall.cloud.assistant.po.common.SteelSystemRegionAreaInfoBeanExample;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author yuchaohua
 * @version V1.0
 * @Title: SteelSystemRegionAreaInfoServiceImpl
 * @Package com.steel.yfmall.cloud.assistant.common.impl
 * @Description: (用一句话描述该文件做什么)
 * @date 2021/1/22 15:41
 */
@Service
@Slf4j
public class SteelSystemRegionAreaInfoServiceImpl implements SteelSystemRegionAreaInfoService {

    /**
     * 参数拼接
     *
     * @param paraBean
     * @return
     */
    private SteelSystemRegionAreaInfoBeanExample assemblyParameters(ParaSteelSystemRegionAreaInfo paraBean) {
        SteelSystemRegionAreaInfoBeanExample example = new SteelSystemRegionAreaInfoBeanExample();
        SteelSystemRegionAreaInfoBeanExample.Criteria criteria = example.createCriteria();
        if (paraBean == null) {
            return example;
        }
        if (StringUtils.isNotBlank(paraBean.getExternalRegionCode())) {
            criteria.andExternalRegionCodeEqualTo(paraBean.getExternalRegionCode());
        }
        if (StringUtils.isNotBlank(paraBean.getParentId())) {
            criteria.andParentIdEqualTo(paraBean.getParentId());
        }
        if (paraBean.getRegionType() != null) {
            criteria.andRegionTypeEqualTo(paraBean.getRegionType());
        }
        if (StringUtils.isNotBlank(paraBean.getRegionId())) {
            criteria.andRegionIdEqualTo(paraBean.getRegionId());
        }
        if (StringUtils.isNotBlank(paraBean.getRegionName())) {
            criteria.andRegionNameEqualTo(paraBean.getRegionName());
        }
        if (!CollectionUtils.isEmpty(paraBean.getRegionIdList())) {
            criteria.andRegionIdIn(paraBean.getRegionIdList());
        }
        if (StringUtils.isNotBlank(paraBean.getOrderByValue())) {
            example.setOrderByClause(paraBean.getOrderByValue());
        }
        return example;
    }

    /**
     * 查询地区表信息Map
     * @Title: getSteelSystemRegionAreaInfoMap
     * @Description: (这里用一句话描述这个方法的作用)
     * @Param paraBean 参数说明
     * @return java.util.Map<java.lang.String,com.steel.yfmall.cloud.assistant.po.common.SteelSystemRegionAreaInfoBean>    返回类型
     * @author yuchaohua
     * @date 2021/1/22 15:46
     */
    @Override
    public Map<String, SteelSystemRegionAreaInfoBean> getSteelSystemRegionAreaInfoMap(ParaSteelSystemRegionAreaInfo paraBean) {
        Map<String, SteelSystemRegionAreaInfoBean> returnBean = null;
        List<SteelSystemRegionAreaInfoBean> dbResultBeans = getSteelSystemRegionAreaInfoBeanByList(paraBean);
        if (!CollectionUtils.isEmpty(dbResultBeans)) {
            returnBean = new HashMap<>();
            for (SteelSystemRegionAreaInfoBean item : dbResultBeans) {
                returnBean.put(item.getRegionId(), item);
            }
        }
        return returnBean;
    }

    /**
     * @description: 查询list集合
     * @date: 2020/6/10 14:12
     * @author: ding
     */
    public List<SteelSystemRegionAreaInfoBean> getSteelSystemRegionAreaInfoBeanByList(ParaSteelSystemRegionAreaInfo paraBean) {
        SteelSystemRegionAreaInfoBeanExample example = assemblyParameters(paraBean);
        return steelSystemRegionAreaInfoBeanMapper.selectByExample(example);
    }

    /**
     * 查询单条信息
     */
    public SteelSystemRegionAreaInfoBean querySingleSteelSystemRegionAreaInfoBean(ParaSteelSystemRegionAreaInfo paraBean) {
        SteelSystemRegionAreaInfoBeanExample example = assemblyParameters(paraBean);
        return steelSystemRegionAreaInfoBeanMapper.selectOneByExampleSelective(example);
    }

    @Resource
    private SteelSystemRegionAreaInfoBeanMapper steelSystemRegionAreaInfoBeanMapper;
}
